package com.mzm.util.persistency;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import dnl.toolbox.time.TimeUtils;

@Entity(name = "TimingInfo")
@Table(name = "TIMING_INFO")
public class TimingInfo implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@TableGenerator(
			name = "ID_GEN",
			table = "ID_GEN",
			pkColumnName = "GEN_KEY",
			valueColumnName = "GEN_VALUE",
			pkColumnValue = "ID",
			allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_GEN")
	protected Integer id;

	@Column(name = "CREATE_TIME")
	private Date creationTime;

	@Column(name = "MODIF_TIME")
	private Date modificationTime;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getCreationTime() {
		return creationTime;
	}

	public void setCreationTime(Date creationTime) {
		this.creationTime = creationTime;
	}

	public Date getModificationTime() {
		return modificationTime;
	}

	public void setModificationTime(Date modificationTime) {
		this.modificationTime = modificationTime;
	}

	@PrePersist
	public void resolveTimingInfo() {
		if (getCreationTime() == null) {
			setCreationTime(TimeUtils.getCurrentTime().toDate());
		}
		setModificationTime(TimeUtils.getCurrentTime().toDate());
	}
	
}
